package com.hjm.project.statistical.snCountData.controller;

import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.framework.web.page.TableDataInfo;
import com.hjm.project.statistical.snCountData.domain.SnCountData;
import com.hjm.project.statistical.snCountData.service.ISnCountDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 终端按月统计Controller
 * 
 * @author maker-platform
 * @date 2021-07-21
 */
@Controller
@RequestMapping("/statistical/SnCountData")
public class SnCountDataController extends BaseController
{
    private String prefix = "statistical/snCountData";

    @Resource
    private ISnCountDataService snCountDataService;

    @RequiresPermissions("SnCountData:SnCountData:view")
    @GetMapping()
    public String SnCountData()
    {
        return prefix + "/snCountData";
    }

    /**
     * 查询终端按月统计列表
     */
    @RequiresPermissions("SnCountData:SnCountData:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SnCountData snCountData) {
        SnCountData sumMoney = snCountDataService.selectSnCountDataSum(snCountData);
        startPage();
        List<SnCountData> list = snCountDataService.selectSnCountDataList(snCountData);
        return getDataTable(list,sumMoney);
    }

    /**
     * 导出终端按月统计列表
     */
    @RequiresPermissions("SnCountData:SnCountData:export")
    @Log(title = "终端按月统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SnCountData snCountData)
    {
        List<SnCountData> list = snCountDataService.selectSnCountDataList(snCountData);
        ExcelUtil<SnCountData> util = new ExcelUtil<SnCountData>(SnCountData.class);
        return util.exportExcel(list, "SnCountData");
    }

    /**
     * 新增终端按月统计
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存终端按月统计
     */
    @RequiresPermissions("SnCountData:SnCountData:add")
    @Log(title = "终端按月统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SnCountData snCountData)
    {
        return toAjax(snCountDataService.insertSnCountData(snCountData));
    }

    /**
     * 修改终端按月统计
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        SnCountData snCountData = snCountDataService.selectSnCountDataById(id);
        mmap.put("snCountData", snCountData);
        return prefix + "/edit";
    }

    /**
     * 修改保存终端按月统计
     */
    @RequiresPermissions("SnCountData:SnCountData:edit")
    @Log(title = "终端按月统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SnCountData snCountData)
    {
        return toAjax(snCountDataService.updateSnCountData(snCountData));
    }

    /**
     * 删除终端按月统计
     */
    @RequiresPermissions("SnCountData:SnCountData:remove")
    @Log(title = "终端按月统计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(snCountDataService.deleteSnCountDataByIds(ids));
    }
}
